@extends('admin.home.main')

@section('body')
    <section id="main-content">
        <section class="wrapper">
            <h3>测试报告添加</h3>
            <!-- BASIC FORM ELELEMNTS -->
            <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel">
                        <form class="form-horizontal style-form" action="/admin/test_report/insert" method="post">
                            <input type="hidden" id="_token" name="_token" value="{{csrf_token()}}">
                            <input type="hidden" id="report_id" name="report_id" value="{{$report_info->id}}">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">测试报告名称</label>
                                <div class="col-sm-10">
                                    <input type="text" style="width:400px;" class="form-control" id="name"
                                           name="name" placeholder="请输入测试报告名称" size="50" value="{{$report_info->name}}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">测试报告内容</label>
                                <div class="col-sm-10">
                                    <script type="text/javascript" charset="utf-8" src="{{asset('ueditor/ueditor.config.js')}}"></script>
                                    <script type="text/javascript" charset="utf-8" src="{{asset('ueditor/ueditor.all.min.js')}}"></script>
                                    <script type="text/javascript" charset="utf-8" src="{{asset('ueditor/lang/zh-cn/zh-cn.js')}}"></script>
                                    <script id="editor" type="text/plain" style="width:600px;height:300px;"></script>
                                    <script>
                                        var ue = UE.getEditor('editor');

                                        var content = '{{$report_info->content}}';
                                        content = escape2Html(content);
                                        ue.ready(function() {
                                            ue.setContent(content);
                                            ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
                                        });

                                        function escape2Html(str) {
                                            if(str.indexOf("&#34;")){
                                                str = str.replace(/&#34;/ig,"&quot;");
                                            }
                                            var arrEntities={'&#34;':'"','lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
                                            return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];});
                                        }

                                    </script>
                                </div>
                            </div>

                            <button type="button" id="save" class="btn btn-success">提交</button>
                            <button type="reset" class="btn btn-primary">重置</button>
                        </form>
                    </div>
                </div>
                <!-- col-lg-12-->
            </div>


        </section>
        <!-- /wrapper -->
    </section>
    <script type="text/javascript">
        $('#save').click(function(){
            var _token = $('#_token').val(),
                _id = $('#report_id').val(),
                _name = $('#name').val(),
                _content = UE.getEditor('editor').getContent();

            if(!_name){
                alert('请输入测试报告名称');
                return false;
            }

            if(!_content){
                alert('请输入测试报告内容');
                return false;
            }

            $.ajax({
                url:'/admin/test_report/save',
                type:'post',
                data:{'_token':_token,'id':_id,'name':_name,'content':_content},
                dataType:'json',
                success:function(msg){
                    if(msg.code == 200){
                        alert('编辑成功');
                        location.href="/admin/test_report/list";
                    }else{
                        alert('编辑失败');
                        location.reload();
                    }
                }
            })
        })
    </script>
@endsection